#!/usr/bin/env bash

copy_stay=`tmux show-environment COPY_STAY`
if [[ -z $copy_stay || $copy_stay == 'COPY_STAY=0' ]]; then
    tmux display-message 'Toggle to copy stay.'
    tmux set-environment COPY_STAY 1
    tmux unbind -T copy-mode-vi y
    tmux bind -T copy-mode-vi y send-keys -X copy-pipe "xclip -in -selection clipboard"\\\; display-message "Copied to system clipboard."
else
    tmux display-message 'Toggle to no copy stay.'
    tmux set-environment COPY_STAY 0
    tmux unbind -T copy-mode-vi y
    tmux bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"
fi
